import unittest
import json
from app import app

class TestLogin(unittest.TestCase):
	"""Test mathfuc.py"""

	def setUp(self):
		self.app = app
		self.client = self.app.test_client

	def test_login_correct(self):
		data = {
			"unique_id": "632718427@qq.com",
			"password": "12345678"
		}
		res = self.client().get('/api/v1/login', data=data)
		res_data = json.loads(res.data)
		self.assertEqual(res.status_code, 200)

	def test_login_unique_id_not_exist(self):
		data = {
			"unique_id": "632718427@qq.com1",
			"password": "123456781"
		}
		res = self.client().get('/api/v1/login', data=data)
		res_data = json.loads(res.data)
		self.assertEqual(res.status_code, 400)
		self.assertEqual(res_data["code"], 'A001')

	def test_login_password_not_correct(self):
		data = {
			"unique_id": "632718427@qq.com",
			"password": "12345678111"
		}
		res = self.client().get('/api/v1/login', data=data)
		res_data = json.loads(res.data)
		self.assertEqual(res.status_code, 400)
		self.assertEqual(res_data["code"], 'A002')


if __name__ == '__main__':
	# verbosity=*：默认是1；设为0，则不输出每一个用例的执行结果；2-输出详细的执行结果
	unittest.main(verbosity=1)